<?php

require_once(CHEMIN_MODELE . "Role.php");
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RoleManager
 *
 * @author Yahn_V
 */
class RoleManager {

    public static function GetRolesUser($login) {
        try {

            $pdo = PDO2::getInstance();


            $requete = $pdo->prepare("SELECT profil FROM AssociationRole a, Role r
		WHERE a.id = r.id and
		login = :nom_utilisateur");

            $requete->bindValue(':nom_utilisateur', $login);

            $requete->execute();
            $result = array();
            while ($donnees = $requete->fetch(PDO::FETCH_ASSOC)) {

                $result[] = $donnees['profil'];
            }
            $requete->closeCursor();
            return $result;
        } catch (PDOException $e) {
            echo '<p>Erreur : ' . $e->getMessage() . '</p>';
            $rtrn = null;
        }
    }

    public static function getAllRole() {
        try {
            $pdo = PDO2::getInstance();
            $requete = $pdo->query("SELECT * FROM Role");
            $result = array();
            while ($donnees = $requete->fetch(PDO::FETCH_OBJ)) {
                $result[] = new Role($donnees->id, $donnees->profil);
            }
            $requete->closeCursor();
            return $result;
        } catch (PDOException $e) {
            echo '<p>Erreur : ' . $e->getMessage() . '</p>';
            $rtrn = null;
        }
    }

    public static function getRoleById($id) {
        try {

            $pdo = PDO2::getInstance();


            $requete = $pdo->prepare("SELECT profil FROM Role r WHERE id = :id");

            $requete->bindValue(':id', $id);

            $requete->execute();
            $result = $requete->fetch(PDO::FETCH_OBJ);
            $role = new Role($id, $result->profil);

            $requete->closeCursor();
            return $role;
        } catch (PDOException $e) {
            echo '<p>Erreur : ' . $e->getMessage() . '</p>';
            $rtrn = null;
        }
    }

}

?>
